﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Simple.Services.System.QHSEUser.Models;

namespace Simple.WebApi.Controllers.System;

/// <summary>
/// 菜单管理
/// </summary>
[Route("QHSESysUser/[action]")]
[ApiController]
public class QHSEUserController : ControllerBase
{
    private readonly QHSEUserService _userService;

    public QHSEUserController(QHSEUserService userService)
    {
        _userService = userService;
    }

    [HttpGet]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> List()
    {
        List<QHSEUserModel> menus = await _userService.GetAsync();
        return AppResult.Status200OK(data: menus);
    }
    [HttpGet]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> Page([FromQuery] QHSEUserPageInputModel model)
    {
        PageResultModel<QHSEUserModel> data = await _userService.GetPageAsync(model);
        return AppResult.Status200OK(data: data);
    }
    [HttpGet]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> PageResult([FromQuery] QHSEUserPageInputModel model)
    {
        PageResultModel<QHSEUserModel> data = await _userService.GetPageResultAsync(model);
        return AppResult.Status200OK(data: data);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> Add([FromBody] QHSEUserModel model)
    {
        await _userService.AddAsync(model);
        return AppResult.Status200OK("新增成功");
    }
    /// <summary>
    /// 获取手机号对应的员工信息
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [ValidateTimestampAndSignature]
    public async Task<IActionResult> GetUser([FromQuery] QHSEMobileInputModel input)
    {
        QHSEUserModel data = await _userService.GetUserInfoByMobileAsync(input);

        return Ok(AppResult.Status200OK(data: data));
    }
    /// <summary>
    /// 获取长庆井下技术作业公司人员列表
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [ValidateTimestampAndSignature]
    public async Task<AppResult> UserList()
    {
        var input = new QHSEUserPageInputModel();
        input.OrganizationName = "长庆井下技术作业公司";
        List<QHSEUserModel> data = await _userService.GetUsersAsync(input);
        return AppResult.Status200OK(data: data);
    }
    /// <summary>
    /// 获取长庆钻井总公司人员列表
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [ValidateTimestampAndSignature]
    public async Task<AppResult> UserList1()
    {
        var input = new QHSEUserPageInputModel();
        input.OrganizationName = "长庆钻井总公司";
        List<QHSEUserModel> data = await _userService.GetUsersAsync(input);
        return AppResult.Status200OK(data: data);
    }
}
